/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import BUS.DichVu_BUS;
import BUS.LoaiPhong_BUS;
import BUS.MonAn_BUS;
import BUS.Phong_BUS;
import DTO.DichVu_DTO;
import DTO.LoaiPhong_DTO;
import DTO.MonAn_DTO;
import DTO.Phong_DTO;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Lenh Ho Xung
 */
public final class FrameChucNang extends javax.swing.JFrame {

    DefaultComboBoxModel cbbModelPhong;
    DefaultTableModel tbModel;
    DefaultTableModel modelLoaiPhong;
    String maDichVu;
    String maMonAn;

    /**
     * Creates new form FrameChucNang
     */
    public FrameChucNang() {
        initComponents();
        this.setSize(852, 650);
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("src/Image/trogiup.png"));
        //form phong
        showdanhsachPhong();
        //hiện thông tin vào combobox loại phòng
        showcbbMaLoaiPhong();
        btXoa_p.setEnabled(false);
        btCapNhat_p.setEnabled(false);

        //loai phong
        showLoaiPhong();
        btCapNhatLoaiPhong.setEnabled(false);
        btXoaLoaiPhong.setEnabled(false);
        try {
            //
            showBangDV();
            showBangMA();
        } catch (Exception ex) {
            Logger.getLogger(FrameChucNang.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    protected void showdanhsachPhong() {
        try {
            tbModel = Phong_BUS.layDanhSachPhong();
            tablePhong.setModel(tbModel);
        } catch (Exception e) {
        }
    }

    protected void showcbbMaLoaiPhong() {

        cbbModelPhong = (DefaultComboBoxModel) cbbMaLoaiPhong.getModel();
        ArrayList<LoaiPhong_DTO> ds = new ArrayList<>();
        try {
            ds = LoaiPhong_BUS.layDanhSachMaLoaiPhong();
        } catch (Exception e) {
        }

        for (LoaiPhong_DTO lp : ds) {
            cbbModelPhong.addElement(lp.getMaloaiPhong());
        }
    }

    public void showLoaiPhong() {
        try {
            modelLoaiPhong = LoaiPhong_BUS.layDanhSachLoaiPhong();
            tbLoaiPhong.setModel(modelLoaiPhong);
        } catch (Exception ex) {
            Logger.getLogger(LoaiPhong.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void showBangMA() throws Exception {
        tbMonAn.setModel(MonAn_BUS.layBangMonAn());
    }

    public void luuMonAn() throws Exception {
        String tenMonAn;
        tenMonAn = tfTenMA.getText();
        if (tenMonAn.equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên món ăn!");
            return;
        }
        Float donGia;
        try {
            donGia = Float.parseFloat(tfDonGiaMA.getText());
            if (donGia < 0 || donGia > 10000000) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!");
                tfDonGiaMA.setText("0");
                return;
            }
        } catch (NumberFormatException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!");
            tfDonGiaMA.setText("0");
            return;
        }
        maMonAn = maMonAn();
        MonAn_DTO ma = new MonAn_DTO();
        ma.setMaMonAn(maMonAn);
        ma.setTenMonAn(tenMonAn);
        ma.setDonGia(donGia.toString());
        MonAn_BUS.Insert(ma);
        JOptionPane.showMessageDialog(rootPane, "Thêm món ăn thành công!");
        showBangMA();
//        ArrayList<MonAn_DTO> lst = new ArrayList();
//        tbMonAn.clearSelection();
//        int i = 0;
//        while (tbMonAn.getValueAt(i, 0) != null) {
//            MonAn_DTO mon = new MonAn_DTO();
//            try {
//                Float f = Float.parseFloat(tbMonAn.getValueAt(i, 1).toString());
//            } catch (Exception e) {
//                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số!");
//                return;
//            }
//            mon.setTenMonAn(tbMonAn.getValueAt(i, 0).toString());
//            mon.setDonGia(tbMonAn.getValueAt(i, 1).toString());
//            lst.add(mon);
//            //MonAn_BUS.Insert(mon);
//            i++;
//        }
//        for (MonAn_DTO m : lst) {
//            String maMon = maMonAn();
//            m.setMaMonAn(maMon);
//            MonAn_BUS.Insert(m);
//        }
//        lst.clear();
//        JOptionPane.showMessageDialog(rootPane, "Thêm món ăn thành công!");
//        tbMonAn.setModel(new DefaultTableModel(tableTitle, 7));
    }

    protected String maMonAn() throws Exception {
        String lastID = MonAn_BUS.layMaCuoiCung();
        String nextID = null;
        try {
            if (lastID != null) {
                nextID = MonAn_BUS.taoMaTuDong(lastID, 3);
            } else {
                nextID = MonAn_BUS.taoMaTuDong("MMA0000", 3);
            }
        } catch (Exception e) {
        }
        return nextID;
    }

    private void showBangDV() throws Exception {
        tbDichVu.setModel(DichVu_BUS.layBangDichVu());
    }

    public void luuDichVu() throws Exception {
        String tenDichVu;
        tenDichVu = tfTenDV.getText();
        if (tenDichVu.equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên dịch vụ!");
            return;
        }
        Float donGia;
        try {
            donGia = Float.parseFloat(tfDonGiaDV.getText());
            if (donGia < 0 || donGia > 10000000) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!");
                tfDonGiaDV.setText("0");
                return;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!!");
            tfDonGiaDV.setText("0");
            return;
        }
        String maDichVu = maDichVu();
        DichVu_DTO dv = new DichVu_DTO();
        dv.setMaDichVu(maDichVu);
        dv.setTenDichVu(tenDichVu);
        dv.setDonGia(donGia.toString());
        DichVu_BUS.Insert(dv);
        JOptionPane.showMessageDialog(rootPane, "Thêm dịch vụ thành công!");

//        ArrayList<DichVu_DTO> lst = new ArrayList();
//        tbDichVu.clearSelection();
//        int i = 0;
//        while (tbDichVu.getValueAt(i, 0) != null) {
//            DichVu_DTO dv = new DichVu_DTO();
//            try {
//                Float f = Float.parseFloat(tbDichVu.getValueAt(i, 1).toString());
//            } catch (Exception e) {
//                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số!");
//                return;
//            }
//            dv.setTenDichVu(tbDichVu.getValueAt(i, 0).toString());
//            dv.setDonGia(tbDichVu.getValueAt(i, 1).toString());
//            lst.add(dv);
//            //MonAn_BUS.Insert(mon);
//            i++;
//        }
//        for (DichVu_DTO m : lst) {
//            String maDV = maDichVu();
//            m.setMaDichVu(maDV);
//            DichVu_BUS.Insert(m);
//        }
//        lst.clear();
//        JOptionPane.showMessageDialog(rootPane, "Thêm dịch vụ thành công!");
//        tbDichVu.setModel(new DefaultTableModel(tableTitle, 7));
    }

    protected String maDichVu() throws Exception {
        String lastID = DichVu_BUS.layMaCuoiCung();
        String nextID = null;
        try {
            if (lastID != null) {
                nextID = DichVu_BUS.taoMaTuDong(lastID, 3);
            } else {
                nextID = DichVu_BUS.taoMaTuDong("MDV0000", 3);
            }
        } catch (Exception e) {
        }
        return nextID;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        pannelPhong = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        tfTenPhong = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        tfGhiChu = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cbbMaLoaiPhong = new javax.swing.JComboBox();
        btCapNhat_p = new javax.swing.JButton();
        btLapPhong_p = new javax.swing.JButton();
        btXoa_p = new javax.swing.JButton();
        tfTenLoaiPhong_p = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePhong = new javax.swing.JTable();
        pannelLoaiPhong = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tfTenLoaiPhong = new javax.swing.JTextField();
        tfDonGia = new javax.swing.JTextField();
        btThemLoaiPhong = new javax.swing.JButton();
        btXoaLoaiPhong = new javax.swing.JButton();
        btCapNhatLoaiPhong = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbLoaiPhong = new javax.swing.JTable();
        pannelDichVu = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tbDichVu = new javax.swing.JTable();
        btThemDV = new javax.swing.JButton();
        btCapNhatDV = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        tfTenDV = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        tfDonGiaDV = new javax.swing.JTextField();
        btXoaDV = new javax.swing.JButton();
        pannelMonAn = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbMonAn = new javax.swing.JTable();
        btThemMA = new javax.swing.JButton();
        btCapNhatMA = new javax.swing.JButton();
        tfTenMA = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        tfDonGiaMA = new javax.swing.JTextField();
        btXoaMA = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setText("Ghi Chú");

        tfGhiChu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfGhiChuActionPerformed(evt);
            }
        });

        jLabel3.setText("Tên Phòng");

        jLabel2.setText("Mã Loại Phòng");

        jLabel4.setText("Tên Loại Phòng");

        cbbMaLoaiPhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbbMaLoaiPhongActionPerformed(evt);
            }
        });

        btCapNhat_p.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Sync.png"))); // NOI18N
        btCapNhat_p.setText("Cập nhật");
        btCapNhat_p.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhat_pActionPerformed(evt);
            }
        });

        btLapPhong_p.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/add.png"))); // NOI18N
        btLapPhong_p.setText("Thêm phòng");
        btLapPhong_p.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLapPhong_pActionPerformed(evt);
            }
        });

        btXoa_p.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Erase.png"))); // NOI18N
        btXoa_p.setText("Xóa");
        btXoa_p.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoa_pActionPerformed(evt);
            }
        });

        tfTenLoaiPhong_p.setEditable(false);
        tfTenLoaiPhong_p.setBackground(new java.awt.Color(204, 204, 204));
        tfTenLoaiPhong_p.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfTenLoaiPhong_pActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfTenPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbbMaLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(btLapPhong_p)
                        .addGap(35, 35, 35)
                        .addComponent(btXoa_p, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btCapNhat_p))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(38, 38, 38)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfTenLoaiPhong_p, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfGhiChu, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCapNhat_p, btLapPhong_p, btXoa_p});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTenPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfGhiChu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(tfTenLoaiPhong_p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btLapPhong_p)
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btCapNhat_p)
                                .addComponent(btXoa_p))))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbMaLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btCapNhat_p, btLapPhong_p, btXoa_p});

        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tablePhong.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        tablePhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        tablePhong.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablePhongMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tablePhong);

        javax.swing.GroupLayout pannelPhongLayout = new javax.swing.GroupLayout(pannelPhong);
        pannelPhong.setLayout(pannelPhongLayout);
        pannelPhongLayout.setHorizontalGroup(
            pannelPhongLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelPhongLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
            .addGroup(pannelPhongLayout.createSequentialGroup()
                .addGap(101, 101, 101)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(225, Short.MAX_VALUE))
        );
        pannelPhongLayout.setVerticalGroup(
            pannelPhongLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelPhongLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Phòng", new javax.swing.ImageIcon(getClass().getResource("/Image/Phong.png")), pannelPhong); // NOI18N

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel5.setText("Tên loại phòng: ");

        jLabel6.setText("Đơn giá:");

        btThemLoaiPhong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/add.png"))); // NOI18N
        btThemLoaiPhong.setText("Thêm loại phòng");
        btThemLoaiPhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemLoaiPhongActionPerformed(evt);
            }
        });

        btXoaLoaiPhong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Erase.png"))); // NOI18N
        btXoaLoaiPhong.setText("Xóa");
        btXoaLoaiPhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoaLoaiPhongActionPerformed(evt);
            }
        });

        btCapNhatLoaiPhong.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Sync.png"))); // NOI18N
        btCapNhatLoaiPhong.setText("Cập nhật");
        btCapNhatLoaiPhong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatLoaiPhongActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(118, 118, 118)
                        .addComponent(btThemLoaiPhong)
                        .addGap(30, 30, 30)
                        .addComponent(btXoaLoaiPhong)
                        .addGap(18, 18, 18)
                        .addComponent(btCapNhatLoaiPhong))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(110, 110, 110)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))
                        .addGap(31, 31, 31)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfTenLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfDonGia, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCapNhatLoaiPhong, btThemLoaiPhong, btXoaLoaiPhong});

        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(tfTenLoaiPhong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(tfDonGia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCapNhatLoaiPhong)
                    .addComponent(btXoaLoaiPhong)
                    .addComponent(btThemLoaiPhong))
                .addGap(20, 20, 20))
        );

        jPanel6Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btCapNhatLoaiPhong, btThemLoaiPhong, btXoaLoaiPhong});

        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tbLoaiPhong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbLoaiPhong.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbLoaiPhongMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tbLoaiPhong);

        javax.swing.GroupLayout pannelLoaiPhongLayout = new javax.swing.GroupLayout(pannelLoaiPhong);
        pannelLoaiPhong.setLayout(pannelLoaiPhongLayout);
        pannelLoaiPhongLayout.setHorizontalGroup(
            pannelLoaiPhongLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelLoaiPhongLayout.createSequentialGroup()
                .addGap(141, 141, 141)
                .addGroup(pannelLoaiPhongLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pannelLoaiPhongLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(281, Short.MAX_VALUE))
        );
        pannelLoaiPhongLayout.setVerticalGroup(
            pannelLoaiPhongLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pannelLoaiPhongLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Loại phòng", new javax.swing.ImageIcon(getClass().getResource("/Image/LoaiPhong.png")), pannelLoaiPhong); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jScrollPane5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tbDichVu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbDichVu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbDichVuMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tbDichVu);

        btThemDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/add.png"))); // NOI18N
        btThemDV.setText("Thêm Dịch Vụ");
        btThemDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemDVActionPerformed(evt);
            }
        });

        btCapNhatDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Sync.png"))); // NOI18N
        btCapNhatDV.setText("Cập Nhật");
        btCapNhatDV.setEnabled(false);
        btCapNhatDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatDVActionPerformed(evt);
            }
        });

        jLabel7.setText("Tên Dịch Vụ");

        jLabel8.setText("Đơn giá");

        tfDonGiaDV.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        tfDonGiaDV.setText("0");

        btXoaDV.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Erase.png"))); // NOI18N
        btXoaDV.setText("Xóa");
        btXoaDV.setEnabled(false);
        btXoaDV.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoaDVActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTenDV, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfDonGiaDV, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(75, 75, 75))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btThemDV)
                .addGap(19, 19, 19)
                .addComponent(btXoaDV, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btCapNhatDV, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(95, 95, 95))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCapNhatDV, btThemDV, btXoaDV});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfTenDV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(tfDonGiaDV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCapNhatDV)
                    .addComponent(btThemDV)
                    .addComponent(btXoaDV))
                .addGap(28, 28, 28)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btThemDV, btXoaDV});

        javax.swing.GroupLayout pannelDichVuLayout = new javax.swing.GroupLayout(pannelDichVu);
        pannelDichVu.setLayout(pannelDichVuLayout);
        pannelDichVuLayout.setHorizontalGroup(
            pannelDichVuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelDichVuLayout.createSequentialGroup()
                .addGap(145, 145, 145)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 531, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(343, Short.MAX_VALUE))
        );
        pannelDichVuLayout.setVerticalGroup(
            pannelDichVuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelDichVuLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Dịch vụ", new javax.swing.ImageIcon(getClass().getResource("/Image/DichVu.png")), pannelDichVu); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jScrollPane4.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tbMonAn.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbMonAn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbMonAnMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tbMonAn);

        btThemMA.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/add.png"))); // NOI18N
        btThemMA.setText("Thêm Món Ăn");
        btThemMA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemMAActionPerformed(evt);
            }
        });

        btCapNhatMA.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Sync.png"))); // NOI18N
        btCapNhatMA.setText("Cập Nhật");
        btCapNhatMA.setEnabled(false);
        btCapNhatMA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCapNhatMAActionPerformed(evt);
            }
        });

        jLabel9.setText("Tên Món Ăn");

        jLabel10.setText("Đơn giá");

        tfDonGiaMA.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        tfDonGiaMA.setText("0");

        btXoaMA.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Erase.png"))); // NOI18N
        btXoaMA.setText("Xóa");
        btXoaMA.setEnabled(false);
        btXoaMA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoaMAActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(99, 99, 99)
                                .addComponent(btThemMA)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btXoaMA, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btCapNhatMA, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tfTenMA, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, Short.MAX_VALUE)
                                .addComponent(jLabel10)
                                .addGap(34, 34, 34)
                                .addComponent(tfDonGiaMA, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(46, Short.MAX_VALUE)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 504, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCapNhatMA, btThemMA, btXoaMA});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(tfTenMA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(tfDonGiaMA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCapNhatMA)
                    .addComponent(btThemMA)
                    .addComponent(btXoaMA))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btCapNhatMA, btThemMA, btXoaMA});

        javax.swing.GroupLayout pannelMonAnLayout = new javax.swing.GroupLayout(pannelMonAn);
        pannelMonAn.setLayout(pannelMonAnLayout);
        pannelMonAnLayout.setHorizontalGroup(
            pannelMonAnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelMonAnLayout.createSequentialGroup()
                .addGap(141, 141, 141)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(314, Short.MAX_VALUE))
        );
        pannelMonAnLayout.setVerticalGroup(
            pannelMonAnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pannelMonAnLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Món ăn", new javax.swing.ImageIcon(getClass().getResource("/Image/trogiup.png")), pannelMonAn); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tfGhiChuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfGhiChuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfGhiChuActionPerformed

    private void cbbMaLoaiPhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbbMaLoaiPhongActionPerformed
        // TODO add your handling code here:
        try {
            tfTenLoaiPhong_p.setText(LoaiPhong_BUS.laytenLoaiPhong(cbbMaLoaiPhong.getSelectedItem().toString()));
        } catch (Exception e) {
        }
    }//GEN-LAST:event_cbbMaLoaiPhongActionPerformed

    private void btCapNhat_pActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhat_pActionPerformed
        // TODO add your handling code here:
        int row = this.tablePhong.getSelectedRow();
        Phong_DTO p = new Phong_DTO();
        String maPhong = (String) this.tbModel.getValueAt(row, 0).toString();
        String tenPhong = tfTenPhong.getText();
        String maloaiPhong = cbbMaLoaiPhong.getSelectedItem().toString();
        String tinhtrang = "Trống";
        String ghiChu = tfGhiChu.getText();

        if (tenPhong.equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên phòng!");
            return;
        }
        p.setMaPhong(maPhong);
        p.setTenPhong(tenPhong);
        p.setMaloaiPhong(maloaiPhong);
        p.setTinhTrang(tinhtrang);
        p.setGhiChu(ghiChu);
        try {
            Phong_BUS.Update(p);
        } catch (Exception e) {
        }
        showdanhsachPhong();
        btXoa_p.setEnabled(false);
        btCapNhat_p.setEnabled(false);

    }//GEN-LAST:event_btCapNhat_pActionPerformed

    private void btLapPhong_pActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLapPhong_pActionPerformed
        // TODO add your handling code here:

        String maPhong;
        int row = this.tablePhong.getRowCount();
        try {
            if (row > 0) {
                maPhong = Phong_BUS.taoMaTuDong(tbModel.getValueAt(row - 1, 0).toString(), 2);
            } else {
                maPhong = Phong_BUS.taoMaTuDong("MP0000", 2);
            }
            String tenPhong = tfTenPhong.getText();
            String maloaiPhong = cbbMaLoaiPhong.getSelectedItem().toString();
            String tinhtrang = "Trống";
            String ghiChu = tfGhiChu.getText();

            if (tenPhong.equals("")) {
                JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên phòng!");
                return;
            }
            Phong_DTO p = new Phong_DTO();
            p.setMaPhong(maPhong);
            p.setTenPhong(tenPhong);
            p.setMaloaiPhong(maloaiPhong);
            p.setTinhTrang(tinhtrang);
            p.setGhiChu(ghiChu);

            Phong_BUS.Insert(p);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
        tfTenPhong.setText("");
        tfGhiChu.setText("");
        cbbMaLoaiPhong.setSelectedIndex(0);
        showdanhsachPhong();
    }//GEN-LAST:event_btLapPhong_pActionPerformed

    private void btXoa_pActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoa_pActionPerformed
        // TODO add your handling code here:
        int row = this.tablePhong.getSelectedRow();
        int show = JOptionPane.showConfirmDialog(rootPane, "Bạn có chắc chắn muốn xóa?", "", JOptionPane.YES_NO_OPTION);
        if (show == JOptionPane.YES_OPTION) {
            try {
                String maPhong = tbModel.getValueAt(row, 0).toString();
                String tinhTrang = (String) tbModel.getValueAt(row, 5).toString();
                if (tinhTrang.equals("Đang đặt")) {
                    JOptionPane.showMessageDialog(rootPane, "Phòng đang đặt không được xóa!");
                    return;
                }
                if (tinhTrang.equals("Đang thuê")) {
                    JOptionPane.showMessageDialog(rootPane, "Phòngđang thuê không được xóa!");
                    return;
                }
                Phong_BUS.Delete(maPhong);

            } catch (Exception e) {
            }
            showdanhsachPhong();
            btXoa_p.setEnabled(false);
            btCapNhat_p.setEnabled(false);
        } else if (show == JOptionPane.NO_OPTION) {
            return;
        }
    }//GEN-LAST:event_btXoa_pActionPerformed

    private void tfTenLoaiPhong_pActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfTenLoaiPhong_pActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfTenLoaiPhong_pActionPerformed

    private void tablePhongMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablePhongMouseClicked
        // TODO add your handling code here:

        int row = this.tablePhong.getSelectedRow();
        if (row >= 0) {
            btXoa_p.setEnabled(true);
            btCapNhat_p.setEnabled(true);
        } else {
        }
        String tenPhong = (String) this.tbModel.getValueAt(row, 2).toString();
        String tenloaiPhong = (String) this.tbModel.getValueAt(row, 3).toString();
        String ghiChu = (String) this.tbModel.getValueAt(row, 6).toString();

        tfTenPhong.setText(tenPhong);
        tfTenLoaiPhong_p.setText(tenloaiPhong);
        if (ghiChu == null) {
            tfGhiChu.setText("");
        } else {
            tfGhiChu.setText(ghiChu);
        }

        cbbMaLoaiPhong.setSelectedItem(this.tbModel.getValueAt(row, 1).toString());

    }//GEN-LAST:event_tablePhongMouseClicked

    private void btThemLoaiPhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemLoaiPhongActionPerformed
        // TODO add your handling code here:
            int rows = tbLoaiPhong.getRowCount();
        float dongia;
        LoaiPhong_DTO p = new LoaiPhong_DTO();
        try {

            if (rows <= 0) {
                p.setMaloaiPhong(Phong_BUS.taoMaTuDong("MLP0000", 3));
            } else {
                p.setMaloaiPhong(Phong_BUS.taoMaTuDong(modelLoaiPhong.getValueAt(rows - 1, 0).toString(), 3));
            }
            if (tfTenLoaiPhong.getText().equals("")) {
                JOptionPane.showMessageDialog(rootPane, "Bạn phải nhập tên loại phòng!");
                return;
            } else {
                p.setTenloaiPhong(tfTenLoaiPhong.getText());
            }

            try {
                dongia = Float.parseFloat(tfDonGia.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số!");
                return;
            }
           
            if (tfDonGia.getText().equals("")) {
                JOptionPane.showMessageDialog(rootPane, "Bạn phải nhập đơn giá!");
                return;
            } else {
                 p.setDonGia(Float.toString(dongia));
            }
            LoaiPhong_BUS.Insert(p);

        } catch (Exception ex) {
            Logger.getLogger(LoaiPhong.class.getName()).log(Level.SEVERE, null, ex);
        }
        showLoaiPhong();
    }//GEN-LAST:event_btThemLoaiPhongActionPerformed

    private void btXoaLoaiPhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoaLoaiPhongActionPerformed
        // TODO add your handling code here:
        int row = this.tbLoaiPhong.getSelectedRow();
       int show = JOptionPane.showConfirmDialog(rootPane, "Bạn có chắc chắn muốn xóa?", "", JOptionPane.YES_NO_OPTION);
        if (show == JOptionPane.YES_OPTION) {     
            try {
            String maloaiPhong = (String) this.modelLoaiPhong.getValueAt(row, 0).toString();
            LoaiPhong_BUS.Delete(maloaiPhong);

        } catch (Exception e) {
        }
        showLoaiPhong();
        }
        else{
            return;
        }
    }//GEN-LAST:event_btXoaLoaiPhongActionPerformed

    private void btCapNhatLoaiPhongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatLoaiPhongActionPerformed
        // TODO add your handling code here:
        int row = tbLoaiPhong.getSelectedRow();
        float dongia;
        LoaiPhong_DTO p = new LoaiPhong_DTO();
        try {
            p.setMaloaiPhong(modelLoaiPhong.getValueAt(row, 0).toString());
            p.setTenloaiPhong(tfTenLoaiPhong.getText());
            try {
                dongia = Float.parseFloat(tfDonGia.getText());
            } catch (Exception e) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số!");
                return;
            }
            p.setDonGia(Float.toString(dongia));
            LoaiPhong_BUS.Update(p);

        } catch (Exception ex) {
            Logger.getLogger(LoaiPhong.class.getName()).log(Level.SEVERE, null, ex);
        }
        showLoaiPhong();
    }//GEN-LAST:event_btCapNhatLoaiPhongActionPerformed

    private void tbLoaiPhongMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbLoaiPhongMouseClicked
        // TODO add your handling code here:
        int row = tbLoaiPhong.getSelectedRow();
        if (row >= 0) {
            btCapNhatLoaiPhong.setEnabled(true);
            btXoaLoaiPhong.setEnabled(true);
        }
        String tenloaiPhong = modelLoaiPhong.getValueAt(row, 1).toString();
        String dongia = modelLoaiPhong.getValueAt(row, 2).toString();
        tfTenLoaiPhong.setText(tenloaiPhong);
        tfDonGia.setText(dongia);
    }//GEN-LAST:event_tbLoaiPhongMouseClicked

    private void tbDichVuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbDichVuMouseClicked
        // TODO add your handling code here:
        int row = tbDichVu.getSelectedRow();
        if (row >= 0) {
            btXoaDV.setEnabled(true);
            btCapNhatDV.setEnabled(true);
            maDichVu = (String) tbDichVu.getValueAt(row, 0);
            String tenDichVu = (String) tbDichVu.getValueAt(row, 1);
            String donGia = tbDichVu.getValueAt(row, 2).toString();
            tfTenDV.setText(tenDichVu);
            tfDonGiaDV.setText(donGia);
        }
    }//GEN-LAST:event_tbDichVuMouseClicked

    private void btThemDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemDVActionPerformed
        // TODO add your handling code here:
        try {
            luuDichVu();
            showBangDV();
        } catch (Exception ex) {
            Logger.getLogger(ThemMonAn.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btThemDVActionPerformed

    private void btCapNhatDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatDVActionPerformed
        // TODO add your handling code here:
        String tenDichVu;
        tenDichVu = tfTenDV.getText();
        if (tenDichVu.equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên dịch vụ!");
            return;
        }
        Float donGia;
        try {
            donGia = Float.parseFloat(tfDonGiaDV.getText());
            if (donGia < 0 || donGia > 10000000) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!");
                tfDonGiaDV.setText("0");
                return;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!!");
            tfDonGiaDV.setText("0");
            return;
        }
        try {
            DichVu_DTO dv = new DichVu_DTO();
            dv.setMaDichVu(maDichVu);
            dv.setTenDichVu(tenDichVu);
            dv.setDonGia(donGia.toString());
            DichVu_BUS.Update(dv);
            showBangDV();
        } catch (Exception ex) {
            Logger.getLogger(ThemDichVu.class.getName()).log(Level.SEVERE, null, ex);
        }
        tfTenDV.setText("");
        tfDonGiaDV.setText("0");
        btXoaDV.setEnabled(false);
        btCapNhatDV.setEnabled(false);
    }//GEN-LAST:event_btCapNhatDVActionPerformed

    private void btXoaDVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoaDVActionPerformed
        // TODO add your handling code here:
        int row = this.tbDichVu.getSelectedRow();
        int xoa = JOptionPane.showConfirmDialog(rootPane, "Bạn có chắc chắn muốn xóa?");
        if (xoa != 0) {
            return;
        }
        try {
            String maDichVuXoa = (String) this.tbDichVu.getValueAt(row, 0).toString();
            if (DichVu_BUS.kiemTraDichVuCoTrongCTPhieuDichVu(maDichVuXoa)) {
                JOptionPane.showMessageDialog(rootPane, "Dịch vụ đã được đặt không thể xóa!");
                return;
            }
            DichVu_BUS.Delete(maDichVuXoa);
            showBangDV();
        } catch (Exception e) {
        }
        tfTenDV.setText("");
        tfDonGiaDV.setText("0");
        btXoaDV.setEnabled(false);
        btCapNhatDV.setEnabled(false);
    }//GEN-LAST:event_btXoaDVActionPerformed

    private void tbMonAnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbMonAnMouseClicked
        // TODO add your handling code here:
        int row = tbMonAn.getSelectedRow();
        if (row >= 0) {
            btXoaMA.setEnabled(true);
            btCapNhatMA.setEnabled(true);
            maMonAn = (String) tbMonAn.getValueAt(row, 0);
            String tenMonAn = (String) tbMonAn.getValueAt(row, 1);
            String donGia = tbMonAn.getValueAt(row, 2).toString();
            tfTenMA.setText(tenMonAn);
            tfDonGiaMA.setText(donGia);
        }
    }//GEN-LAST:event_tbMonAnMouseClicked

    private void btThemMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemMAActionPerformed
        // TODO add your handling code here:
        try {
            luuMonAn();
            showBangMA();
        } catch (Exception ex) {
            Logger.getLogger(ThemMonAn.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btThemMAActionPerformed

    private void btCapNhatMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCapNhatMAActionPerformed
        // TODO add your handling code here:
        String tenMonAn;
        tenMonAn = tfTenMA.getText();
        if (tenMonAn.equals("")) {
            JOptionPane.showMessageDialog(rootPane, "Bạn chưa nhập tên món ăn!");
            return;
        }
        Float donGia;
        try {
            donGia = Float.parseFloat(tfDonGiaMA.getText());
            if (donGia < 0 || donGia > 10000000) {
                JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!");
                tfDonGiaMA.setText("0");
                return;
            }
        } catch (NumberFormatException | HeadlessException e) {
            JOptionPane.showMessageDialog(rootPane, "Đơn giá phải là số từ 0 đến 10.000.000!!");
            tfDonGiaMA.setText("0");
            return;
        }
        try {
            MonAn_DTO ma = new MonAn_DTO();
            ma.setMaMonAn(maMonAn);
            ma.setTenMonAn(tenMonAn);
            ma.setDonGia(donGia.toString());
            MonAn_BUS.Update(ma);
            showBangMA();
        } catch (Exception ex) {
            Logger.getLogger(ThemDichVu.class.getName()).log(Level.SEVERE, null, ex);
        }
        tfTenMA.setText("");
        tfDonGiaMA.setText("0");
        btXoaMA.setEnabled(false);
        btCapNhatMA.setEnabled(false);
    }//GEN-LAST:event_btCapNhatMAActionPerformed

    private void btXoaMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoaMAActionPerformed
        // TODO add your handling code here:
        int row = this.tbMonAn.getSelectedRow();
        int xoa = JOptionPane.showConfirmDialog(rootPane, "Bạn có chắc chắn muốn xóa?");
        if (xoa != 0) {
            return;
        }
        try {
            String maMonAnXoa = (String) this.tbMonAn.getValueAt(row, 0).toString();
            if (MonAn_BUS.kiemTraMonAnCoTrongCTPhieuDatTiec(maMonAnXoa)) {
                JOptionPane.showMessageDialog(rootPane, "Món ăn đã được đặt tiệc không thể xóa!");
                return;
            }
            MonAn_BUS.Delete(maMonAnXoa);
            showBangMA();
        } catch (Exception e) {
        }
        tfTenMA.setText("");
        tfDonGiaMA.setText("0");
        btXoaMA.setEnabled(false);
        btCapNhatMA.setEnabled(false);
    }//GEN-LAST:event_btXoaMAActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        FrameMenu.menu.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        // TODO add your handling code here:
        this.setLocationRelativeTo(FrameMenu.menu.pannelDestop);
    }//GEN-LAST:event_formComponentMoved

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameChucNang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameChucNang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameChucNang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameChucNang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrameChucNang().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCapNhatDV;
    private javax.swing.JButton btCapNhatLoaiPhong;
    private javax.swing.JButton btCapNhatMA;
    private javax.swing.JButton btCapNhat_p;
    private javax.swing.JButton btLapPhong_p;
    private javax.swing.JButton btThemDV;
    private javax.swing.JButton btThemLoaiPhong;
    private javax.swing.JButton btThemMA;
    private javax.swing.JButton btXoaDV;
    private javax.swing.JButton btXoaLoaiPhong;
    private javax.swing.JButton btXoaMA;
    private javax.swing.JButton btXoa_p;
    private javax.swing.JComboBox cbbMaLoaiPhong;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel pannelDichVu;
    private javax.swing.JPanel pannelLoaiPhong;
    private javax.swing.JPanel pannelMonAn;
    private javax.swing.JPanel pannelPhong;
    private javax.swing.JTable tablePhong;
    private javax.swing.JTable tbDichVu;
    private javax.swing.JTable tbLoaiPhong;
    private javax.swing.JTable tbMonAn;
    private javax.swing.JTextField tfDonGia;
    private javax.swing.JTextField tfDonGiaDV;
    private javax.swing.JTextField tfDonGiaMA;
    private javax.swing.JTextField tfGhiChu;
    private javax.swing.JTextField tfTenDV;
    private javax.swing.JTextField tfTenLoaiPhong;
    private javax.swing.JTextField tfTenLoaiPhong_p;
    private javax.swing.JTextField tfTenMA;
    private javax.swing.JTextField tfTenPhong;
    // End of variables declaration//GEN-END:variables
}
